/*********************************************************************************
 *      Copyright:  (C) 2022 Li Yanting<liyanting2@163.com>
 *                  All rights reserved.
 *
 *       Filename:  main.h
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(05/06/2022)
 *         Author:  Li Yanting <liyanting2@163.com>
 *      ChangeLog:  1, Release initial version on "05/06/2022 06:06:07"
 *                 
 ********************************************************************************/
#ifndef _MAIN_H_
#define _MAIN_H_

#include <stdlib.h>
#include <signal.h>
#include <getopt.h>
#include <pthread.h>
#include <stdio.h>
#include <mosquitto.h>
#include <errno.h>
#include <getopt.h>
#include <stdlib.h>
#include <signal.h>
#include <sqlite3.h>
#include "get_ctx_conf.h"
#include "pack_data.h"
#include "client_sqlite.h"
#include "get_time.h"
#include "serial.h"
#include "at_cmd.h"
#include "pdu.h"
#include "switch.h"
#include "ds18b20.h"
#include "logger.h"

#define LOG_PATH "../data/running.log"
#define INI_PATH "./mqtt_conf.ini"

#define MAX_SEND_SMS_LEN 256

static int level = LOG_LEVEL_INFO;
static int g_stop = 0;
static int g_listen_stop = 0;
static int g_uploat_stop;
static char g_specify_num[16] = "+86xxxxxxxxxxx";
static int g_interval_time = 5;
static int g_threshold = 30;
static int g_warn_time = 600; //second

typedef void *(THREAD_BODY) (void *thread_arg);
int thread_start(pthread_t *thread_id, THREAD_BODY *thread_workbody, void *thread_arg);
void *thread_switch(void *ctx);
void *thread_mqtt(void *ctx);

static inline void print_help();
static inline void print_usage(char *proname);
static inline void prog_stop(int sig_num);
static inline void adjust_buf(char *buf);
int identify_sms_type(char *sms_message, int sms_message_len);

void message_callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message);
void connect_callback(struct mosquitto *mosq, void *obj, int rc);
void *thread_reconnect(void *ctx);

#endif